import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import java.util.Random;

import toolkit.tianshi.common.time.DateHelper;

public class CreateData {

    private final LoadingCache<String, Method> methodLoadingCache = CacheBuilder.newBuilder().build(new CacheLoader<String, Method>() {
        @Override
        public Method load(String key) throws Exception {
            Method method = OrderModel.class.getMethod(key, String.class);
            return method;
        }
    });

    public Map<String, String > createTitle() {
        Map<String, String > map = Maps.newHashMap();
        map.put("vendorName", "君の名は");
        map.put("startTime", DateHelper.getYestoday());
        map.put("endTime", DateHelper.getCurrentDate());
        return map;
    }

    public List<Object> createData() throws InvocationTargetException, IllegalAccessException {
        List<Object> list = Lists.newArrayList();
        for (int i = 0 ;i<1000;i++){
            OrderModel orderModel = new OrderModel();
            for (int j =1 ;j <=7 ;j++) {
                Method method = methodLoadingCache.getUnchecked("setNumber" + j);
                method.invoke(orderModel, String.valueOf(i)+"--"+String.valueOf(j));
            }
            list.add(orderModel);
        }
        try {
            Random random = new Random();
            Integer time = random.nextInt(2000) + 1;
            System.out.println(time);
            Thread.sleep(time);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
}
